package com.dc.designPattern._13_command.impl;

/**
 * Description: 命令模式_客户端
 * @author: gdc
 * @date: 2021/4/20
 * @version 1.0
 */
public class Client {

    public static void main(String[] args){
        // step 1 创建接收者  灯
        LightReceiver lightReceiver = new LightReceiver();

        // step 2 创建命令    灯相关命令
        LightOnCommand lightOnCommand = new LightOnCommand(lightReceiver);
        LightOffCommand lightOffCommand = new LightOffCommand(lightReceiver);

        // step 3 创建调用者  遥控器
        RemoteController controller = new RemoteController();
        
        // step 4 给调用者设置命令，例如 no = 0, 是电灯的开关操作
        controller.setCommand(0, lightOnCommand, lightOffCommand);

        System.out.println("------------按下灯的开操作-------------");
        controller.onButtonWasPushed(0);
        System.out.println("------------按下灯的关操作-------------");
        controller.offButtonWasPushed(0);
        System.out.println("------------撤销操作-------------");
        controller.undoButtonWasPushed();


        System.out.println("=========使用遥控器操作电视机==========");

        TvReceiver tvReceiver = new TvReceiver();
        TvOnCommand tvOnCommand = new TvOnCommand(tvReceiver);
        TvOffCommand tvOffCommand = new TvOffCommand(tvReceiver);

        //给我们的遥控器设置命令, 比如 no = 1 是电视机的开和关的操作
        controller.setCommand(1, tvOnCommand, tvOffCommand);

        System.out.println("------------按下电视的开操作-------------");
        controller.onButtonWasPushed(1);
        System.out.println("------------按下电视的关操作-------------");
        controller.offButtonWasPushed(1);
        System.out.println("------------撤销操作-------------");
        controller.undoButtonWasPushed();

    }
}
